package com.atguigui.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 386.字典序排数
 * <p>
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2022/4/20 08:42
 */
public class P386LexicographicalNumbers {
    public static void main(String[] args) {
        Solution solution = new P386LexicographicalNumbers().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<Integer> lexicalOrder(int n) {
            String stringValue[] = new String[n];
            //循环遍历
            for (int i = 0; i < n; i++) {
                stringValue[i] = String.valueOf(i + 1);
            }
            //使用string排序
            Arrays.sort(stringValue);
            List<Integer> ans = new ArrayList<>();
            //存放在List中返回
            for (int i = 0; i < n; i++) {
                ans.add(Integer.parseInt(stringValue[i]));
            }
            return ans;
        }
    }
}
